package com.zbkj.crmeb.store.controller;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.zbkj.crmeb.store.request.StoreProductDistributeRequest;
import com.zbkj.crmeb.store.response.StoreProductDistributeResponse;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.service.StoreProductDistributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "商品分发")
@RequestMapping("/api/admin/store/product/distribute")
public class StoreProductDistributeController{
    @Autowired
    StoreProductDistributeService storeProductDistributeService;

    /**
     * 功能描述: 新增/修改商品组信息
     * @Param: [request]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.Boolean>
     * @Author: wangzh
     * @Date: 2022/11/11 14:11
     */
    @ApiOperation("保存/修改商品组信息")
    @PostMapping
    public CommonResult<Boolean> saveProductGroup(@RequestBody StoreProductDistributeRequest request){
        return CommonResult.success(storeProductDistributeService.saveProductGroup(request));
    }

    /**
     * 功能描述: 传入id与页码获取详细信息
     * @Param: [id, page]
     * @Return: com.crmeb.core.common.CommonResult<com.zbkj.crmeb.store.response.StoreProductDistributeResponse>
     * @Author: wangzh
     * @Date: 2022/11/11 15:17
     */
    @ApiOperation("根据商品组id获取详细信息")
    @GetMapping("/{id}")
    public CommonResult<StoreProductDistributeResponse> getProductGroupById(@PathVariable Integer id){
        return CommonResult.success(storeProductDistributeService.getProductGroupById(id));
    }

    /**
     * 功能描述: 根据分页条件查询列表/传入名称模糊搜索
     * @Param: [request]
     * @Return: com.crmeb.core.common.CommonResult<com.common.CommonPage<com.zbkj.crmeb.store.response.StoreProductDistributeResponse>>
     * @Author: wangzh
     * @Date: 2022/11/11 15:31
     */
    @ApiOperation("获取商品分发列表/模糊搜索商品组")
    @GetMapping
    public CommonResult<CommonPage<StoreProductDistributeResponse>> getProductGroupList(String name, PageParamRequest request){
        return CommonResult.success(CommonPage.restPage(storeProductDistributeService.getProductGroupList(name, request)));
    }

    /**
     * 功能描述: 通过传入的商品分发id与要分发商品的商户id，完成商品的上架
     * @Param: [request]
     * @Return: com.crmeb.core.common.CommonResult<java.lang.Boolean>
     * @Author: wangzh
     * @Date: 2022/11/14 11:09
     */
    @ApiOperation("分发商户")
    @PutMapping
    public CommonResult<Boolean> distributeProductToSupplier(@RequestBody StoreProductDistributeRequest request){
        return CommonResult.success(storeProductDistributeService.distributeProductToSupplier(request));
    }

    @ApiOperation("删除商品组")
    @DeleteMapping("/{id}")
    public CommonResult<Boolean> deleteProductGroupById(@PathVariable Integer id){
        return CommonResult.success(storeProductDistributeService.deleteProductGroupById(id));
    }

}
